package com.hzhr.iot.user.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.user.convertor.custom.DeptCustomConvertor;
import com.hzhr.iot.user.dao.DeptDao;
import com.hzhr.iot.user.dao.helper.DeptDaoHelper;
import com.hzhr.iot.user.entity.DeptEntity;
import com.hzhr.iot.user.entity.ext.DeptEntityExt;
import com.hzhr.iot.user.model.dept.DeptDeleteModel;
import com.hzhr.iot.user.model.dept.DeptGetModel;
import com.hzhr.iot.user.model.dept.DeptModel;
import com.hzhr.iot.user.model.dept.DeptPostModel;
import com.hzhr.iot.user.queryModel.custom.DeptCustomQueryModel;
import com.hzhr.iot.user.service.base.BaseService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;
import java.util.Map;

@Service
@CygService(entity = DeptEntity.class, model = DeptModel.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),
        @CygQuery(name = "_equal_name", query = "equal_name", type = String.class),
        @CygQuery(name = "_equal_companyId", query = "equal_companyId", type = Integer.class),
        @CygQuery(name = "_equal_level", query = "equal_level", type = Integer.class),
        @CygQuery(name = "_equal_parentId", query = "equal_parentId", type = Integer.class),
        @CygQuery(name = "_like_resourceCode", query = "like_resourceCode", type = String.class),
        @CygQuery(name = "_in_id", query = "in_id", type = List.class),
        @CygQuery(name = "_like_code", query = "like_code", type = String.class),
        @CygQuery(name = "_equal_code", query = "equal_code", type = String.class),
        @CygQuery(name = "_lessthanorequal_level", query = "lessthanorequal_level", type = Integer.class),

})
public class DeptService extends BaseService {
    @Autowired
    UserService userService;
    @Autowired
    DeptCustomConvertor deptCustomConvertor;
    @Autowired
    DeptDao deptDao;
    @Autowired
    DeptService deptService;
    @Autowired
    CompanyService companyService;
    @Autowired
    DeptDaoHelper deptDaoHelper;

    //region javadoc注释 : post
    /**
     * 在登录用户的公司下创建非顶级部门 <br/><br/>
     * 简介&nbsp;:&nbsp;在登录用户的公司下创建非顶级部门 <br/>
     * 术语&nbsp;: <br/>
     * 1.&nbsp;部门(DEPT)的直接下级部门： <br/>
     * &nbsp;满足以下条件的部门(DEPT)对象dept_1可以称作部门(DEPT)对象dept_2的直接下级部门： <br/>
     * &nbsp;(1)&nbsp;dept_1.parentId&nbsp;=&nbsp;dept_2； <br/>
     * 步骤&nbsp;: <br/>
     * 1.&nbsp;验证上级部门编号&nbsp;: <br/>
     * &nbsp;查询部门(DEPT)对象dept_1，查询规则如下： <br/>
     * &nbsp;(1)&nbsp;dept_1.id&nbsp;=&nbsp;body.parentId； <br/>
     * &nbsp;(2)&nbsp;dept_1.companyId&nbsp;=&nbsp;登录用户.companyId； <br/>
     * &nbsp;如果dept_1不存在，抛出异常201； <br/>
     * 2.&nbsp;验证部门名称&nbsp;: <br/>
     * &nbsp;如果存在部门(DEPT)对象dept满足以下条件，则抛出异常202： <br/>
     * &nbsp;(1)&nbsp;dept.name&nbsp;=&nbsp;body.name <br/>
     * 3.&nbsp;创建部门&nbsp;: <br/>
     * &nbsp;根据body创建部门(DEPT)对象dept_2，并设置以下属性： <br/>
     * &nbsp;(1)&nbsp;dept_2.code的设置规则： <br/>
     * &nbsp;如果dept_1不存在直接下级部门，那么：dept_2.code&nbsp;=&nbsp;dept_1.code&nbsp;+&nbsp;'01'； <br/>
     * &nbsp;如果dept_1存在直接下级部门，查询出dept_1的直接下级部门中code值最大的部门(DEPT)对象，提取出该对象的code的最后两位，转换为数字并在此基础上&nbsp;+1&nbsp;， <br/>
     * &nbsp;然后左补零至两位字符串str_1，最后：dept_2.code&nbsp;=&nbsp;dept_1.code&nbsp;+&nbsp;str_1； <br/>
     * &nbsp;(2)&nbsp;dept_2.resourceCode的设置规则： <br/>
     * &nbsp;如果dept_1不存在直接下级部门，那么：dept_2.resourceCode&nbsp;=&nbsp;dept_1.resourceCode&nbsp;+&nbsp;'01'； <br/>
     * &nbsp;如果dept_1存在直接下级部门，查询出dept_1的直接下级部门中resourceCode值最大的部门(DEPT)对象，提取出该对象的resourceCode的最后两位，转换为数字并在此基础上&nbsp;+1&nbsp;， <br/>
     * &nbsp;然后左补零至两位字符串str_1，最后：dept_2.resourceCode&nbsp;=&nbsp;dept_1.resourceCode&nbsp;+&nbsp;str_1； <br/>
     * &nbsp;(3)&nbsp;dept_2.level&nbsp;=&nbsp;dept_1.level&nbsp;+&nbsp;1； <br/>
     * &nbsp;(4)&nbsp;dept_2.parentName&nbsp;=&nbsp;dept_1.name； <br/>
     * &nbsp;(5)&nbsp;dept_2.companyId&nbsp;=&nbsp;dept_1.companyId； <br/>
     * 4.&nbsp;返回信息&nbsp;: <br/>
     * &nbsp;调用“查询部门”服务(user-service:&nbsp;/depts&nbsp;GET)获取“部门模型(查询)”对象result，调用规则如下： <br/>
     * &nbsp;(1)&nbsp;accessMode:&nbsp;GLOBAL <br/>
     * &nbsp;(2)&nbsp;query:&nbsp;_equal_id&nbsp;=&nbsp;dept_2.id <br/>
     * &nbsp;设置result属性，设置规则如下： <br/>
     * &nbsp;(1)&nbsp;result.changeCount&nbsp;=&nbsp;创建数量； <br/>
     * &nbsp;返回result； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * DEPTSERVICE_POST_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证上级部门<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 上级部门不存在<br/>
     * DEPTSERVICE_POST_202 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证部门名称<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 部门名称已存在<br/>
     * @see DeptPostModel body <br/>
     * @see DeptGetModel result <br/>
     */ 
    //endregion
    //region 说明 : post
    //在登录用户的公司下创建非顶级部门
    //简介 : 在登录用户的公司下创建非顶级部门
    //术语 :
    //1. 部门(DEPT)的直接下级部门：
    // 满足以下条件的部门(DEPT)对象dept_1可以称作部门(DEPT)对象dept_2的直接下级部门：
    // (1) dept_1.parentId = dept_2；
    //步骤 :
    //1. 验证上级部门编号 :
    // 查询部门(DEPT)对象dept_1，查询规则如下：
    // (1) dept_1.id = body.parentId；
    // (2) dept_1.companyId = 登录用户.companyId；
    // 如果dept_1不存在，抛出异常201；
    //2. 验证部门名称 :
    // 如果存在部门(DEPT)对象dept满足以下条件，则抛出异常202：
    // (1) dept.name = body.name
    //3. 创建部门 :
    // 根据body创建部门(DEPT)对象dept_2，并设置以下属性：
    // (1) dept_2.code的设置规则：
    // 如果dept_1不存在直接下级部门，那么：dept_2.code = dept_1.code + '01'；
    // 如果dept_1存在直接下级部门，查询出dept_1的直接下级部门中code值最大的部门(DEPT)对象，提取出该对象的code的最后两位，转换为数字并在此基础上 +1 ，
    // 然后左补零至两位字符串str_1，最后：dept_2.code = dept_1.code + str_1；
    // (2) dept_2.resourceCode的设置规则：
    // 如果dept_1不存在直接下级部门，那么：dept_2.resourceCode = dept_1.resourceCode + '01'；
    // 如果dept_1存在直接下级部门，查询出dept_1的直接下级部门中resourceCode值最大的部门(DEPT)对象，提取出该对象的resourceCode的最后两位，转换为数字并在此基础上 +1 ，
    // 然后左补零至两位字符串str_1，最后：dept_2.resourceCode = dept_1.resourceCode + str_1；
    // (3) dept_2.level = dept_1.level + 1；
    // (4) dept_2.parentName = dept_1.name；
    // (5) dept_2.companyId = dept_1.companyId；
    //4. 返回信息 :
    // 调用“查询部门”服务(user-service: /depts GET)获取“部门模型(查询)”对象result，调用规则如下：
    // (1) accessMode: GLOBAL
    // (2) query: _equal_id = dept_2.id
    // 设置result属性，设置规则如下：
    // (1) result.changeCount = 创建数量；
    // 返回result；
    //endregion
    //region 参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/depts", method = RequestMethod.POST)
    //endregion
    @Transactional(rollbackFor = Exception.class)
    public DeptGetModel post(Map<String, String> header, Map<String, Object> query,
                                  DeptPostModel body) throws ServiceException {
        return null;
    }

    //region javadoc注释 : deleteById
    /**
     * 在登录用户的公司下删除非顶级部门 <br/><br/>
     * 简介&nbsp;:&nbsp;删除部门 <br/>
     * 术语&nbsp;: <br/>
     * 1.&nbsp;部门(DEPT)的直接下级部门： <br/>
     * &nbsp;满足以下条件的部门(DEPT)对象dept_1可以称作部门(DEPT)对象dept_2的直接下级部门： <br/>
     * &nbsp;(1)&nbsp;dept_1.parentId&nbsp;=&nbsp;dept_2； <br/>
     * 2.&nbsp;部门(DEPT)的下级用户： <br/>
     * &nbsp;满足以下条件的用户(USER)对象user_1可以称作部门(DEPT)对象dept_1的下级用户： <br/>
     * &nbsp;(1)&nbsp;user_1.dept_id&nbsp;=&nbsp;dept_1.id； <br/>
     * 步骤&nbsp;: <br/>
     * 1.&nbsp;查询部门&nbsp;: <br/>
     * &nbsp;根据路径参数deptId查询部门(DEPT)dept_1，查询规则如下： <br/>
     * &nbsp;(1)&nbsp;dept_1.id&nbsp;=&nbsp;路径参数deptId； <br/>
     * &nbsp;如果dept_1不存在，抛出异常201； <br/>
     * 2.&nbsp;验证部门是否具备删除条件&nbsp;: <br/>
     * &nbsp;如果dept_1存在直接下级部门或下级用户，则抛出异常202； <br/>
     * 3.&nbsp;删除部门&nbsp;: <br/>
     * &nbsp;删除dept_1； <br/>
     * 4.&nbsp;返回信息&nbsp;: <br/>
     * &nbsp;生成“部门模型(删除)”对象result，并设置以下属性： <br/>
     * &nbsp;(1)&nbsp;result.changeCount&nbsp;=&nbsp;删除数量； <br/>
     * &nbsp;返回result； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param deptId 部门编号 <br/><br/>
     * @throws ServiceException <br/>
     * DEPTSERVICE_DELETE_BY_ID_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 查询部门<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 部门不存在<br/>
     * DEPTSERVICE_DELETE_BY_ID_202 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证部门是否具备删除条件<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 存在下级部门或下级用户，无法删除<br/>
     * @see DeptDeleteModel result <br/>
     */ 
    //endregion
    //region 说明 : deleteById
    //在登录用户的公司下删除非顶级部门
    //简介 : 删除部门
    //术语 :
    //1. 部门(DEPT)的直接下级部门：
    // 满足以下条件的部门(DEPT)对象dept_1可以称作部门(DEPT)对象dept_2的直接下级部门：
    // (1) dept_1.parentId = dept_2；
    //2. 部门(DEPT)的下级用户：
    // 满足以下条件的用户(USER)对象user_1可以称作部门(DEPT)对象dept_1的下级用户：
    // (1) user_1.dept_id = dept_1.id；
    //步骤 :
    //1. 查询部门 :
    // 根据路径参数deptId查询部门(DEPT)dept_1，查询规则如下：
    // (1) dept_1.id = 路径参数deptId；
    // 如果dept_1不存在，抛出异常201；
    //2. 验证部门是否具备删除条件 :
    // 如果dept_1存在直接下级部门或下级用户，则抛出异常202；
    //3. 删除部门 :
    // 删除dept_1；
    //4. 返回信息 :
    // 生成“部门模型(删除)”对象result，并设置以下属性：
    // (1) result.changeCount = 删除数量；
    // 返回result；
    //endregion
    //region 参数 : deleteById
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "deptId", value = "部门编号",required = true, dataType = "int", paramType = "path"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : deleteById
    @RequestMapping(value = "/depts/{deptId}", method = RequestMethod.DELETE)
    //endregion
    @Transactional(rollbackFor = Exception.class)
    public DeptDeleteModel deleteById(Map<String, String> header, Integer deptId, Map<String, Object> query) throws ServiceException {
        return null;
    }

    //region javadoc注释 : get
    /**
     * 查询部门 <br/><br/>
     * 简介&nbsp;:&nbsp;查询部门 <br/>
     * 步骤&nbsp;: <br/>
     * 1.&nbsp;查询部门&nbsp;:&nbsp;(√) <br/>
     * &nbsp;根据条件参数查询部门(DEPT)； <br/>
     * 2.&nbsp;返回信息&nbsp;:&nbsp;(√) <br/>
     * &nbsp;根据条件参数和查询到的结果组装响应并返回，响应模型的部分属性获取规则如下： <br/>
     * &nbsp;(1)&nbsp;“部门模型”对象deptModel_1.managementName的获取规则： <br/>
     * &nbsp;如果查询结果部门(DEPT)对象dept_1.level&nbsp;小于等于&nbsp;3，deptModel_1.managementName&nbsp;=&nbsp;dept_1.name， <br/>
     * &nbsp;否则，取出dept_1.code的前9位字符串str_1，并查询出部门(DEPT)dept_2，其中dept_2.code&nbsp;=&nbsp;str_1， <br/>
     * &nbsp;最后，deptModel_1.managementName&nbsp;=&nbsp;dept_2.name； <br/>
     * &nbsp;(2)&nbsp;“部门模型”对象deptModel_1.subCompanyName的获取规则： <br/>
     * &nbsp;如果查询结果部门(DEPT)对象dept_1.level&nbsp;小于等于&nbsp;2，deptModel_1.subCompanyName&nbsp;=&nbsp;dept_1.name， <br/>
     * &nbsp;否则，取出dept_1.code的前7位字符串str_1，并查询出部门(DEPT)dept_2，其中dept_2.code&nbsp;=&nbsp;str_1， <br/>
     * &nbsp;最后，deptModel_1.subCompanyName&nbsp;=&nbsp;dept_2.name； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_managementName : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示管理站名称;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_subCompanyName : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示分公司名称;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _is_paging : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _in_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.id in #{_in_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.name = #{_equal_name};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_companyId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.companyId = #{_equal_companyId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_level : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.level = #{_equal_level};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_parentId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.parentId = #{_equal_parentId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _like_resourceCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.resourceCode like #{_like_resourceCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _like_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.code like #{_like_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.code = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _lessthanorequal_level : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where DEPT.level <= #{_lessthanorequal_level};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @throws ServiceException <br/>
     * @see DeptGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get
    //查询部门
    //简介 : 查询部门
    //步骤 :
    //1. 查询部门 : (√)
    // 根据条件参数查询部门(DEPT)；
    //2. 返回信息 : (√)
    // 根据条件参数和查询到的结果组装响应并返回，响应模型的部分属性获取规则如下：
    // (1) “部门模型”对象deptModel_1.managementName的获取规则：
    // 如果查询结果部门(DEPT)对象dept_1.level 小于等于 3，deptModel_1.managementName = dept_1.name，
    // 否则，取出dept_1.code的前9位字符串str_1，并查询出部门(DEPT)dept_2，其中dept_2.code = str_1，
    // 最后，deptModel_1.managementName = dept_2.name；
    // (2) “部门模型”对象deptModel_1.subCompanyName的获取规则：
    // 如果查询结果部门(DEPT)对象dept_1.level 小于等于 2，deptModel_1.subCompanyName = dept_1.name，
    // 否则，取出dept_1.code的前7位字符串str_1，并查询出部门(DEPT)dept_2，其中dept_2.code = str_1，
    // 最后，deptModel_1.subCompanyName = dept_2.name；
    //endregion
    //region 参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_managementName", value = "是否展示管理站名称", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_subCompanyName", value = "是否展示分公司名称", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "页数", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where DeptModel.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "in_id", value = "筛选条件 : where DeptModel.id in #{in_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_name", value = "筛选条件 : where DeptModel.name = #{equal_name}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_level", value = "筛选条件 : where DeptModel.level = #{equal_level}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_parentId", value = "筛选条件 : where DeptModel.parentId = #{equal_parentId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_companyId", value = "筛选条件 : where DeptModel.companyId = #{equal_companyId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_code", value = "筛选条件 : where DeptModel.code = #{equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "lessthanorequal_level", value = "筛选条件 : where DeptModel.level <= #{lessthanorequal_level}",required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_managementName", value = "是否展示管理站名称", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_subCompanyName", value = "是否展示分公司名称", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "页数", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where DEPT.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_in_id", value = "筛选条件 : where DEPT.id in #{_in_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_name", value = "筛选条件 : where DEPT.name = #{_equal_name}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_companyId", value = "筛选条件 : where DEPT.companyId = #{_equal_companyId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_level", value = "筛选条件 : where DEPT.level = #{_equal_level}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_parentId", value = "筛选条件 : where DEPT.parentId = #{_equal_parentId}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_like_resourceCode", value = "筛选条件 : where DEPT.resourceCode like #{_like_resourceCode}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_like_code", value = "筛选条件 : where DEPT.code like #{_like_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_code", value = "筛选条件 : where DEPT.code = #{_equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_lessthanorequal_level", value = "筛选条件 : where DEPT.level <= #{_lessthanorequal_level}",required = false, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/depts", method = RequestMethod.GET)
    //endregion
    public DeptGetModel get(Map <String, String> header, Map<String, Object> query) throws ServiceException {
        /* 查询部门 */
        //生成查询模型
        DeptCustomQueryModel queryModel = deptCustomConvertor.deptService_query2queryModel(query);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        Boolean showSubCompanyName = HzhrTypeUtil.object2boolean(query.get("_show_subCompanyName"));
        Boolean showManagementName = HzhrTypeUtil.object2boolean(query.get("_show_managementName"));
        if (showSubCompanyName != null && showSubCompanyName) {
            queryModel.setShow(true);
        }
        if (showManagementName != null && showManagementName) {
            queryModel.setShow(true);
        }
        //查询实体
        List<DeptEntityExt> extList = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (!StringUtils.isEmpty(show)) {
            extList = deptDao.selectExtList(queryModel);
        }
        //查询数量
        Integer total = null;
        Boolean showTotal = HzhrTypeUtil.object2boolean(query.get("_show_total"));
        if (showTotal != null && showTotal) {
            total = deptDao.selectCount(queryModel);
        }

        /* 返回信息 */
        DeptGetModel result = deptCustomConvertor.extList2deptGetModel(extList, total, null, query);
        List<DeptModel> deptModels = result.getModelList();
        if (deptModels != null && deptModels.size() > 0) {
            if (showSubCompanyName != null && showSubCompanyName) {
                for (int i = 0; i < deptModels.size(); i++) {
                    DeptModel deptModel_1 = deptModels.get(i);
                    DeptEntityExt dept_1 = extList.get(i);
                    int level = dept_1.getLevel();
                    if (level <= 2) {
                        deptModel_1.setSubCompanyName(dept_1.getName());
                    } else {
                        String code = dept_1.getCode();
                        String[] split = code.split("-");
                        String code1 = split[0];
                        String code2 = split[1];
                        String str_1 = code1 + "-" + code2.substring(0, 4);
                        DeptEntity dept_2 = deptDaoHelper.getByCode(str_1);
                        if (dept_2 != null) {
                            deptModel_1.setSubCompanyName(dept_2.getName());
                        }
                    }
                }
            }
            if (showManagementName != null && showManagementName) {
                for (int i = 0; i < deptModels.size(); i++) {
                    DeptModel deptModel_1 = deptModels.get(i);
                    DeptEntityExt dept_1 = extList.get(i);
                    int level = dept_1.getLevel();
                    if (level <= 3) {
                        deptModel_1.setManagementName(dept_1.getName());
                    } else {
                        String code = dept_1.getCode();
                        String[] split = code.split("-");
                        String code1 = split[0];
                        String code2 = split[1];
                        String str_1 = code1 + "-" + code2.substring(0, 6);
                        DeptEntity dept_2 = deptDaoHelper.getByCode(str_1);
                        if (dept_2 != null) {
                            deptModel_1.setManagementName(dept_2.getName());
                        }
                    }
                }
            }
        }
        DeptModel deptModel = result.getModel();
        if (deptModel != null) {
            if (showSubCompanyName != null && showSubCompanyName) {
                DeptEntityExt dept_1 = extList.get(0);
                int level = dept_1.getLevel();
                if (level <= 2) {
                    deptModel.setSubCompanyName(dept_1.getName());
                } else {
                    String code = dept_1.getCode();
                    String[] split = code.split("-");
                    String code1 = split[0];
                    String code2 = split[1];
                    String str_1 = code1 + "-" + code2.substring(0, 4);
                    DeptEntity dept_2 = deptDaoHelper.getByCode(str_1);
                    if (dept_2 != null) {
                        deptModel.setSubCompanyName(dept_2.getName());
                    }
                }
            }
            if (showManagementName != null && showManagementName) {
                DeptEntityExt dept_1 = extList.get(0);
                int level = dept_1.getLevel();
                if (level <= 3) {
                    deptModel.setManagementName(dept_1.getName());
                } else {
                    String code = dept_1.getCode();
                    String[] split = code.split("-");
                    String code1 = split[0];
                    String code2 = split[1];
                    String str_1 = code1 + "-" + code2.substring(0, 6);
                    DeptEntity dept_2 = deptDaoHelper.getByCode(str_1);
                    if (dept_2 != null) {
                        deptModel.setManagementName(dept_2.getName());
                    }
                }
            }
        }
        return result;
    }
}










































































































































































































































































































































































































